#!/bin/bash


#calculates n factional where n is first argument of the script

function factorial()
{	
	if [ $1 -eq 0 -o $1 -eq 1 ]; then
		res=1
	else
		factorial $(($1-1))
		res=$(($1*$res))
	fi
}


if [ $# -eq 0 ]; then
	echo "Please provide number for which factorial should be calculated"
	exit 1
fi 

result=1

factorial $1
result=$res

echo $result


